<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>天天生鲜-注册</title>
	<link rel="stylesheet" type="text/css" href="/css/reset.css">
	<link rel="stylesheet" type="text/css" href="/css/main.css">
	<script type="text/javascript" src="/js/jquery-1.12.4.min.js"></script>
	<!--<script type="text/javascript" src="/js/register.js"></script>-->
	<script src="/js/jquery-1.12.4.min.js"></script>

</head>
<body>
	<div class="register_con">
		<div class="l_con fl">
			<a class="reg_logo"><img src="/images/logo02.png"></a>
			<div class="reg_slogan">足不出户  ·  新鲜每一天</div>
			<div class="reg_banner"></div>
		</div>

		<div class="r_con fr">
			<div class="reg_title clearfix">
				<h1>用户注册</h1>
				<a href="login.html">登录</a>
			</div>
			<div class="reg_form clearfix">
				<form id="formInfo">
				<ul>
					<li>
						<label>用户名:</label>
						<input type="text" name="username" id="user_name" onblur="checkname()" >
						<span class="error_tip" id="errName">提示信息</span>
					</li>					
					<li>
						<label>密码:</label>
						<input type="password" name="password" id="pwd">
						<span class="error_tip">提示信息</span>
					</li>
					<li>
						<label>确认密码:</label>
						<input type="password"  id="cpwd" onblur="checkpwd()">
						<span class="error_tip" id="errcpwd">提示信息</span>
					</li>
					<li>
						<label>邮箱:</label>
						<input type="text" name="email" id="email" onblur="checkemail()">
						<span class="error_tip" id="erremail">提示信息</span>
					</li>
					<li class="agreement">
						<input type="checkbox" name="allow" id="allow" checked="checked">
						<label>同意”天天生鲜用户使用协议“</label>
						<span class="error_tip2">提示信息</span>
					</li>
					<li class="reg_sub">
						<input type="button" value="注 册"  onclick="postdata()">
					</li>
				</ul>				
				</form>
			</div>

		</div>

	</div>

	<div class="footer no-mp">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>

<script type="text/javascript">
	<!--验证用户名是否重复-->
	function checkname() {
	   var len= $("#user_name").val().length;
	   console.log(len)
	   if (len>2&&len<9){
           $("#user_name").next().hide();
           namestate=true;
	   }else {
           $("#user_name").next().text("用户名要3-8个字符").show();
           namestate=false;
	   }




	    var username=$("#user_name").val();
	   console.log(username)
	    $.ajax({
			url:"/user/checkname",
			data:{"username":username},
			type:"post",
			dataType:"json",
			success:function (result) {
				if (result.code==0){

				    return;
				} else {

				    $("#errName").html(result.msg).show()
				}
            },
			error:function () {
                $("#errName").html("数据回传失败 请联系管理员")
            }
		})

    }

    function checkemail() {
        var em = /^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$/;
		var em2=$("#email").val();
		if (em.test(em2)){
            $("#email").next().hide();
            emailstate=true;
		} else {
		    $("#erremail").text("邮箱格式不正确").show();
            emailstate=false;
		}

    }

    function checkpwd() {
		var pwd =$("#pwd").val();
		var cpwd =$("#cpwd").val();
		if (cpwd!=pwd){
		    $("#errcpwd").html("密码输入不一致").show();
		    cpwd=false;
		}else {
            $("#errcpwd").hide();
            cpwd=true;
		}
	}

	function postdata() {
        if (namestate && emailstate && cpwd) {
           var data= $("#formInfo").serialize();
           console.log(data);
            alert("注册成功");
            $.ajax({
				url: "/user/register",
				data:data,
				type: "post",
				dataType: "json",
				success:function (result) {
					if (result.code==0){
					    location.href="/user/login"
					} else {
					    $("#erremail").html(result.msg).show();
					}
                },
				error:function () {
                    $("#erremail").html("数据回传失败请联系管理员").show();
                }
			})
        }
    }

</script>
	
</body>
</html>